package com.wg.entity;
/***********************************************************************
 * Module:  User.java
 * Author:  13229
 * Purpose: Defines the Class User
 ***********************************************************************/


import com.wg.model.ObjectZip;
import lombok.Data;

import java.util.ArrayList;
import java.util.Arrays;
@Data
public class User  implements ObjectZip {
   public int id;
   /**
    * 工号
    */
   public String jobNo;
   public String name;
   /**
    * 邮箱
    */
   public String email;
   /**
    * 简介
    */
   public String brief;
   /**
    * 密码
    */
   public String password;
   /**
    * 创建的WG列表(id)
    */
   public ArrayList ownedWG = new ArrayList<>();;
   /**
    * 加入的WG列表(id)
    */
   public ArrayList joinedWG = new ArrayList<>();;
   /**
    * 关注的WG列表(id)
    */
   public ArrayList focusedWG = new ArrayList<>();;
   /**
    * 学习信息,暂时设置为目录
    */
   public String studyInfo;



   @Override
   public String serialize() {
      return id + ":" + jobNo + ":" + name + ":" + email + ":" + brief + ":" + password + ":"
              + JoinArrayList(ownedWG, ",") + ":" + JoinArrayList(joinedWG, ",") + ":"
              + JoinArrayList(focusedWG, ",") + ":" + studyInfo;
   }

   @Override
   public void deserialize(String info) {
      ArrayList list = new ArrayList(Arrays.asList(info.split(":")));

      id = Integer.parseInt((String) list.get(0));
      jobNo = (String)list.get(1);
      name = (String)list.get(2);
      email = (String)list.get(3);
      brief = (String)list.get(4);
      password = (String)list.get(5);
      ownedWG = new ArrayList(Arrays.asList(((String)list.get(6)).split(",")));
      joinedWG = new ArrayList(Arrays.asList(((String)list.get(7)).split(",")));
      focusedWG = new ArrayList(Arrays.asList(((String)list.get(8)).split(",")));
      studyInfo = (String)list.get(9);
   }

   String JoinArrayList(ArrayList list, String joinStr){
      String ret = "";

      for (int i = 0; i < list.size(); i++) {
         if (i != 0){
            ret += joinStr;
         }
         ret += list.get(i);
      }

      return ret;
   }
}